# -*- coding: utf-8 -*-

#=================
#File: PyOpenCV.py
#Author: Wendy
#Date: 2013-12-03
#=================

#eclipse, python2.7, opencv 2.4.6

import cv2

#获得视频的格式
#videoCapture = cv2.VideoCapture('d:/movie/hh/IMG_2515.mp4')
videoCapture = cv2.VideoCapture(0)
#获得码率及尺寸
fps = videoCapture.get(cv2.CAP_PROP_FPS)
size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
        int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))

#指定写视频的格式, I420-avi, MJPG-mp4
#videoWriter = cv2.VideoWriter('oto_other.mp4',cv2.VideoWriter_fourcc('M','J','P','G'), fps, size)

#读帧
while videoCapture.isOpened() :
    success, frame = videoCapture.read()
    cv2.imshow('image',frame) #显示
    k = cv2.waitKey(23) #延迟
    #videoWriter.write(frame) #写视频帧
    if (k & 0xff == ord('q')):
        break
#videoWriter.release()
videoCapture.release()
cv2.destroyAllWindows()